<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //防止父类方法被子类重写，为子类申请命名空间
        var res= []
        var namespace1 = {
            eat :function(num){
                console.log('这是namespace1的eat方法')
                return res.push(num)
            },
            //方法之间可以通过this进行使用
            play:function(s){
                this.eat(s)
                console.log('这是namespace1的play方法')
            }
        }
        var namespace2 = {
            eat :function(num){
                console.log('这是namespace2的eat方法')
                return res.push(num)
            },
            //方法之间可以通过this进行使用
            play:function(s){
                
                console.log('这是namespace2的play方法')
            }
        }
        namespace1.eat(5)
        namespace1.play(6)
        console.log(res)


        //只有获值器，没有赋值器，实现静态变量
        var Conf =(function(){
            var conf = {
                MAX_NUM:100,
                MIN_NUM:1,
                COUNT:1000
            }
            //返回取值器
            return {
                get:function(name){
                    return conf[name] ? conf[name]:null
                }
            }
        })()
        var count = Conf.get('COUNT')
        console.log(count)
        //惰性单例
        var lazySinger = function(){
            var _instance  = null
            function singe(){
                return{
                    publicmethod :function(){},
                    publicpro:'1.0'
                }
            }
            return function(){
                if(!_instance){
                    _instance = singe()
                }
                return _instance
            }
        }
    </script>
</body>
</html>